package com.ys.nms.module.business.controller.admin.otheroid;

import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.ys.nms.framework.common.pojo.PageParam;
import com.ys.nms.framework.common.pojo.PageResult;
import com.ys.nms.framework.common.pojo.CommonResult;
import com.ys.nms.framework.common.util.object.BeanUtils;
import static com.ys.nms.framework.common.pojo.CommonResult.success;

import com.ys.nms.framework.excel.core.util.ExcelUtils;

import com.ys.nms.framework.apilog.core.annotation.ApiAccessLog;
import static com.ys.nms.framework.apilog.core.enums.OperateTypeEnum.*;

import com.ys.nms.module.business.controller.admin.otheroid.vo.*;
import com.ys.nms.module.business.dal.dataobject.otheroid.OtherOidDO;
import com.ys.nms.module.business.service.otheroid.OtherOidService;

@Tag(name = "管理后台 - 补充其它OID")
@RestController
@RequestMapping("/business/other-oid")
@Validated
public class OtherOidController {

    @Resource
    private OtherOidService otherOidService;

    @PostMapping("/create")
    @Operation(summary = "创建补充其它OID")
    public CommonResult<Long> createOtherOid(@Valid @RequestBody OtherOidSaveReqVO createReqVO) {
        return success(otherOidService.createOtherOid(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新补充其它OID")
    public CommonResult<Boolean> updateOtherOid(@Valid @RequestBody OtherOidSaveReqVO updateReqVO) {
        otherOidService.updateOtherOid(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除补充其它OID")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteOtherOid(@RequestParam("id") Long id) {
        otherOidService.deleteOtherOid(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除补充其它OID")
    public CommonResult<Boolean> deleteOtherOidList(@RequestParam("ids") List<Long> ids) {
        otherOidService.deleteOtherOidListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得补充其它OID")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<OtherOidRespVO> getOtherOid(@RequestParam("id") Long id) {
        OtherOidDO otherOid = otherOidService.getOtherOid(id);
        return success(BeanUtils.toBean(otherOid, OtherOidRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得补充其它OID分页")
    public CommonResult<PageResult<OtherOidRespVO>> getOtherOidPage(@Valid OtherOidPageReqVO pageReqVO) {
        PageResult<OtherOidDO> pageResult = otherOidService.getOtherOidPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, OtherOidRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出补充其它OID Excel")
    @ApiAccessLog(operateType = EXPORT)
    public void exportOtherOidExcel(@Valid OtherOidPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<OtherOidDO> list = otherOidService.getOtherOidPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "补充其它OID.xls", "数据", OtherOidRespVO.class,
                        BeanUtils.toBean(list, OtherOidRespVO.class));
    }

}